package com.epin.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.epin.business.system.entity.bo.UserNormal;


public class SessionUtil {
	
	/**
	 * 返回用户的IP地址
	 * @param request
	 * @return
	 */
	public static String getUserIP() {
		Subject subject = SecurityUtils.getSubject();
		return subject.getSession().getHost();
	}
	
	
	/**
	 * 
	 * @return
	 */
	public static UserNormal getCurrentUser() {
		Subject subject = SecurityUtils.getSubject();
		UserNormal sessionUser = (UserNormal) subject.getSession().getAttribute("userSession");
		return sessionUser;
	}
	
	
	/**
	 * 
	 * @param key
	 * @return
	 */
	public static Object getAttr(Object key) {
		Subject subject = SecurityUtils.getSubject();
		return subject.getSession().getAttribute(key);
	}
	
	
	/**
	 * 获取登录用户的userId
	 * @return
	 */
	public static Integer getloginUserId() {
		return getCurrentUser().getId();
	}
	
	
	/**
	 * 获取登录用户的accountName
	 * @return
	 */
	public static String getloginUserAccountName() {
		return getCurrentUser().getAccountName();
	}
	
}
